package com.cjm.one.controller.coupon;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.coupon.dto.CouponReserveDto;
import com.cjm.one.model.coupon.entity.CustomerCoupon;
import com.cjm.one.model.coupon.vo.CouponInfoVo;
import com.cjm.one.service.CustomerCouponService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Tag(name = "用户优惠卷", description = "用户优惠卷")
@RequestMapping("/api/customer/coupon")
public class CustomerCouponController {
    @Resource
    private CustomerCouponService customerCouponService;
    @GetMapping("/list")
    @Operation(summary = "查询用户领取的优惠卷信息列表")
    public Result<Page<CouponInfoVo>> getList(@RequestParam Long current,
                                              @RequestParam Long size ,
                                              @RequestParam(name = "keyWord", required = false) String keyWord,
                                              @RequestParam(name = "rangeType", required = false) Integer rangeType) {
        return customerCouponService.getList(current, size,keyWord, rangeType) ;
    }
    @PostMapping("/receive")
    @Operation(summary = "领取优惠券信息")
    public Result<Boolean> save(@RequestBody CustomerCoupon customerCoupon) {
        return customerCouponService.save(customerCoupon);
    }
    @PostMapping("/receive/auto")
    @Operation(summary = "自动领取优惠券信息")
    public Result<Boolean> autoReceive(@RequestBody @Validated CouponReserveDto couponReserveDto) {
        return customerCouponService.autoReceive(couponReserveDto);
    }
}
